function generateRandomSchool() {
  const schools = [
    "清华大学",
    "北京大学",
    "复旦大学",
    "上海交通大学",
    "浙江大学",
    "南京大学",
    "武汉大学",
    "中山大学",
    "哈尔滨工业大学",
    "四川大学",
    "西安交通大学",
    "华中科技大学",
    "同济大学",
    "电子科技大学",
    "南开大学",
    "吉林大学",
    "大连理工大学",
    "山东大学",
    "华南理工大学",
    "中南大学"
    // 在这里添加更多学校名称
  ];

  const randomIndex = Math.floor(Math.random() * schools.length);
  const randomSchool = schools[randomIndex];

  return randomSchool;
}
//学校

function generateRandomAge() {
  const minAge = 16;
  const maxAge = 20;

  const randomAge = Math.floor(Math.random() * (maxAge - minAge + 1)) + minAge;

  return randomAge;
}
//年龄

function generateRandomGender() {
  const genders = ["男", "女"];

  const randomIndex = Math.floor(Math.random() * genders.length);
  const randomGender = genders[randomIndex];

  return randomGender;
}
//性别

function generateRandomFullName() {


  function generateRandomLastName() {
    const lastNames = [
      "张", "王", "李", "赵", "刘", "陈", "杨", "黄", "吴", "周",
      "徐", "孙", "胡", "朱", "高", "林", "何", "郭", "马", "罗",
      "梁", "宋", "郑", "谢", "韩", "唐", "冯", "于", "董", "萧",
      "程", "曹", "袁", "邓", "许", "傅", "沈", "曾", "彭", "吕"
      // 在这里添加更多姓氏
    ];

    const randomIndex = Math.floor(Math.random() * lastNames.length);
    const randomLastName = lastNames[randomIndex];

    return randomLastName;
  }
  function generateRandomFirstName() {
    const firstNames = [
      "小明", "小红", "小李", "小华", "小强", "小芳", "小刚", "小雨", "小亮", "小丽",
      "嘉欣", "建华", "佳佳", "静静", "俊杰", "娟娟", "君婷", "凯文", "兰兰", "雷锋",
      "梅梅", "敏敏", "楠楠", "平平", "琪琪", "庆庆", "蓉蓉", "盛杰", "石磊", "婷婷",
      "伟伟", "雯雯", "晓东", "欣欣", "艳艳", "阳阳", "小宇", "怡怡", "云云", "哲哲"
      // 在这里添加更多名字
    ];

    const randomIndex = Math.floor(Math.random() * firstNames.length);
    const randomFirstName = firstNames[randomIndex];

    return randomFirstName;
  }


  const randomLastName = generateRandomLastName();
  const randomFirstName = generateRandomFirstName();

  const fullName = randomLastName + randomFirstName;
  return fullName;
}
//姓名

function generateRandomClass() {
  const minClass = 1;
  const maxClass = 4;

  const randomClass = Math.floor(Math.random() * (maxClass - minClass + 1)) + minClass;

  return randomClass + "班";
}
//班级

function generateRandomMajor() {
  const majors = ["计算机科学", "电子工程", "化学工程", "机械工程", "生物学", "数学", "物理学", "经济学", "文学", "历史学", "艺术设计", "心理学", "社会学"];

  const randomIndex = Math.floor(Math.random() * majors.length);
  const randomMajor = majors[randomIndex];

  return randomMajor;
}
//专业

function generateRandomChinesePhoneNumber() {
  const secondPart = Math.floor(Math.random() * (8999 - 1000 + 1)) + 1000;
  const thirdPart = Math.floor(Math.random() * (9999 - 1000 + 1)) + 1000;

  const randomPhoneNumber = `1${secondPart}${thirdPart}`;

  return randomPhoneNumber;
}
//电话

function generateRandomAddress() {
  const cities = ["北京", "上海", "广州", "深圳", "成都", "杭州", "南京", "重庆", "武汉", "西安"];
  const streets = ["中山路", "人民路", "长江路", "和平街", "建设路", "青年路", "文化街", "光明路", "新华路", "西湖路"];

  const randomCity = cities[Math.floor(Math.random() * cities.length)];
  const randomStreet = streets[Math.floor(Math.random() * streets.length)];
  const randomNumber = Math.floor(Math.random() * 100) + 1; // 生成1到100的随机门牌号

  const randomAddress = `${randomCity}${randomStreet}${randomNumber}号`;

  return randomAddress;
}
//住址

function generateRandomIdNumber() {
  function getRandomDate() {
    const year = Math.floor(Math.random() * (2003 - 1980 + 1)) + 1980; // 假设生成在1980年到2003年之间的生日
    const month = Math.floor(Math.random() * 12) + 1;
    const day = Math.floor(Math.random() * 28) + 1; // 简化，不考虑闰年

    return `${year}${month.toString().padStart(2, '0')}${day.toString().padStart(2, '0')}`;
  }
  const randomBirthDate = getRandomDate();
  const randomSequence = Math.floor(Math.random() * 899) + 100; // 生成三位随机顺序码

  // 拼接身份证号码
  const idNumber = `5${randomBirthDate}${randomSequence}X`;

  return idNumber;
}
//身份证

function generateRandomEnrollmentDate() {
  const year = Math.floor(Math.random() * (2023 - 1980 + 1)) + 1980; // 假设生成在1980年到2023年之间的入学年份
  const month = Math.floor(Math.random() * 12) + 1;
  const day = Math.floor(Math.random() * 28) + 1; // 简化，不考虑闰年

  const enrollmentDate = `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`;

  return enrollmentDate;
}
//时间

function generateRandomComment() {
  const comments = [
    "学习优秀",
    "表现出色",
    "进步明显",
    "积极参与",
    "态度认真",
    "团队合作好",
    "创意十足",
    "乐于助人",
    "责任心强",
    "独立思考能力强"
    // 在这里添加更多备注文本
  ];

  const randomIndex = Math.floor(Math.random() * comments.length);
  const randomComment = comments[randomIndex];

  return randomComment;
}
//备注


function insert() {
  for (let i = 0; i < 10; i++) {
    const students = {
      'name': generateRandomFullName(),
      'sex': generateRandomGender(),
      'age': generateRandomAge(),
      'College': generateRandomSchool(),
      'class': generateRandomClass(),
      'specialized': generateRandomMajor(),
      'guardian': generateRandomFullName(),
      'phone': generateRandomChinesePhoneNumber(),
      'address': generateRandomAddress(),
      'identityCard': generateRandomIdNumber(),
      'EnrollmenTime': generateRandomEnrollmentDate(),
      'remark': generateRandomComment(),
    };

    const query = 'INSERT INTO students SET ?';
    connect.query(query, students, function (err, results, fields) {
      if (err) throw err;
      console.log(`插入成功，插入的数据ID为: ${results.insertId}`);
      
      // 在所有插入操作完成后再关闭连接
      if (i === 99) {
        connect.end(function (err) {
          if (err) {
            console.error('关闭连接失败: ' + err.stack);
            return;
          }
          console.log('已关闭数据库连接');
        });
      }
    });
  }
}
// insert()
/**
 * CREATE TABLE students (
         id INT AUTO_INCREMENT PRIMARY KEY,
          name VARCHAR(255) NOT NULL,
          sex VARCHAR(10) NOT NULL,
          age INT,
          College VARCHAR(255),
          class VARCHAR(20),
          specialized VARCHAR(255),
          guardian VARCHAR(255),
          phone VARCHAR(20),
          address VARCHAR(255),
          identityCard VARCHAR(20),
          EnrollmenTime DATE,
          remark TEXT
    );
 */